package Ep01_Array.Feb21st_1360;

import java.util.*;
import java.text.*;

/**
 * @author Jimmy Zhan WORKSTATION
 * @Date 2023/2/21 9:44
 * 说明：力扣 1360，计算两个日期之间差多少天
 */

public class Mine {
    public static void main(String[] args) {
        Mine feb21st = new Mine();
        int days = feb21st.differentDaysByMilliseconds("2020-01-15", "2019-12-31");
        System.out.println(days);
    }

    public int differentDaysByMilliseconds(String date1, String date2){
        java.text.SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
        String str1 = date1;
        String str2 = date2;
        Date d1 = new Date();
        Date d2 = new Date();
        try{
            d1 = simpleDateFormat.parse(str1);
            d2 = simpleDateFormat.parse(str2);
        } catch (ParseException e){
            e.printStackTrace();
            System.out.println("date转换异常");
        }
        int days = Math.abs((int)((d2.getTime() - d1.getTime())/(24*3600*1000)));
        return days;
    }
}
